<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>机房管理-添加机房</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css?v=2.0.4.2}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form>
            <div class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">机房地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="RoomAddr" lay-verify="required" lay-reqtext="机房地址不能为空" placeholder="请输入机房地址"  value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">机房容量</label>
                    <div class="layui-input-block">
                        <input type="number" name="RoomCap" lay-verify="required" lay-reqtext="机房容量不能为空" placeholder="请输入机房容量"  value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">校区</label>
                    <div class="layui-input-block">
                        <select name="campus" lay-verify="required">
                            <option value="">请选择</option>
                            <option value="1">花津校区</option>
                            <option value="2">赭山校区</option>
                            <option value="3">天门山校区</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">空闲时间</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="aempty" title="上午" lay-skin="primary" checked value="1" class="layui-input">
                        <input type="checkbox" name="pempty" title="下午" lay-skin="primary" checked value="1" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button id="btn-submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js?v=2.0.0}" charset="utf-8"></script>
<script>

    layui.use(['form','miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab;
        var $=layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            //异步请求提交数据
            $.ajax({
                url:"/addRoom/add", //传参接口
                data:data.field,
                success:function (response) {
                    if(response.state==200){
                        //成功提示
                        layer.msg(response.message, {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            setTimeout('window.location.reload()',1000)
                        });
                    }else {
                        $("#btn-submit").removeAttr("disabled","disabled").addClass("layui-btn-disabled");
                        layer.msg("添加失败！", {
                            icon: 2,
                            anim: 6
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>